# Old-fashioned regression results for all relative importance models
rm(list=ls())

# Check that required packages are installed:
want = c("foreign", "texreg", "here")
have = want %in% rownames(installed.packages())
if ( any(!have) ) { install.packages( want[!have] ) }
# load packages
junk <- lapply(want, library, character.only = TRUE)
rm(have,want,junk)

options(scipen=999)

load("allmodels.RData")

models.lm <- list()
for (i in unique(data.un$syslab)[order(unique(data.un$syslab))]) {
  pties <- names(table(subset(data.un, syslab == i)$close_party_full))
  ivs <- c("female", "age", "edlow", "edhigh", "clasd1", "clasd2", "clasd4", "clasd5",
           "churchat", "churchat_sq", "standard", "standard_sq", "relig", "relig_sq",
           "i2ImmCus", "i1PriEnt", "i3SamSex", "i1StaOwn", "i3AboFree", "i1IntEco",
           "i3HarSen", "i1OrdRed", "i3ObeAut", "i3WorCut", "i2ImmDec",
           "i2ImmCus_sq", "i1PriEnt_sq", "i3SamSex_sq", "i1StaOwn_sq", "i3AboFree_sq", "i1IntEco_sq",
           "i3HarSen_sq", "i1OrdRed_sq", "i3ObeAut_sq", "i3WorCut_sq", "i2ImmDec_sq")
  np <- paste0("close_str_", pties)
  fml <- as.formula(paste0("lrsp ~ ", paste(c(ivs, np), collapse = "+")))
  mod <- lm(formula = fml,
            data = subset(data.un, syslab == i))
  models.lm[[i]] <- mod
  print(i)
}

htmlreg(models.lm, file = "relimp_lm_table.doc", 
        inline.css = FALSE, doctype = TRUE, html.tag = TRUE, head.tag = TRUE, body.tag = TRUE)
